package com.ggh.jinjilive.remotedata;

import android.text.TextUtils;

import com.alibaba.android.arouter.launcher.ARouter;
import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.ggh.jinjilive.common.StatusConstant;
import com.ggh.jinjilive.mobile.ResultEntity;
import com.ggh.jinjilive.ui.TotalPageActivity;
import com.ggh.jinjilive.ui.login.LoginActivity;
import com.ggh.jinjilive.utils.ARouterUtils;

import io.reactivex.annotations.NonNull;
import io.reactivex.observers.DisposableObserver;

public abstract class InterceptObserver<T> extends DisposableObserver<ResultEntity> implements IObserver{

    @Override
    protected void onStart() {
        super.onStart();

    }

    @Override
    public void onNext(@NonNull ResultEntity resultEntity) {
        if(resultEntity.getCode() == StatusConstant.SUCCESS_199){
            ToastUtils.showShort(resultEntity.getMsg());
        }else if(resultEntity.getCode() == StatusConstant.SUCCESS_999){
            onNextData(resultEntity);
        }else if(resultEntity.getCode() == StatusConstant.SUCCESS_1001){
            onErrorNet(null,resultEntity.getMsg());
        }else if(resultEntity.getCode() == StatusConstant.SUCCESS_1919){
            LogUtils.d("SUCCESS_1919" );
            //启动 Activity
            ActivityUtils.startActivity(LoginActivity.class);
            // 结束除最新之外的所有 Activity
            ActivityUtils.finishAllActivitiesExceptNewest();
        }else if(resultEntity.getCode() == StatusConstant.SUCCESS_2000){
            LogUtils.d("SUCCESS_2000" );
            //启动 Activity
            ActivityUtils.startActivity(LoginActivity.class);
            // 结束除最新之外的所有 Activity
            ActivityUtils.finishAllActivitiesExceptNewest();
        }else {
            LogUtils.d(resultEntity.getMsg());
            ToastUtils.make().show(resultEntity.getMsg());
            onErrorNet(null,resultEntity.getMsg());
        }
    }

    @Override
    public void onError(@NonNull Throwable e) {
        LogUtils.d(e.getMessage());
        ToastUtils.showShort(e.getMessage());
        onErrorNet(null,e.getMessage());
    }

    @Override
    public void onComplete() {
        onFinish();
    }

    @Override
    public boolean isShowToast() {
        return true;
    }


    @Override
    public void onFinish() {

    }

    @Override
    public void onDataEmpty(String netMsg) {
        ToastUtils.showShort(netMsg);
    }

    @Override
    public void onNoData(String netMsg) {

    }
}
